<template>
  <el-container class="home-container">
    <!-- 头部区域 -->
    <el-header class="headerContainer">
      <div class="logoContainer" @click="goHomeRage">
        <img src="@/assets/WDM.jpg" alt="" width="60px" />
        <span class="logoName">智慧学伴管理员系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主体区域 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px' : '200px'">
        <div class="toggle-button" @click="toggleCollapse">
          <i :class="flexibleIcon"></i>
        </div>
        <!-- 侧边栏菜单区域 -->
        <el-menu :collapse="isCollapse" :collapse-transition="false" :default-active="activePath" background-color="#333744" text-color="#fff" active-text-color="#409EFF" router class="asideContainer">
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-upload2"></i>
              <span slot="title">资源管理</span>
            </template>
            <el-menu-item index="resousemanagement" @click="saveNavState('resousemanagement')">资源列表</el-menu-item>
            <el-menu-item index="upload" @click="saveNavState('upload')">资源上传</el-menu-item>
          </el-submenu>
          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-message"></i>
              <span slot="title">意见管理</span>
            </template>
            <el-menu-item index="advicemanagement" @click="saveNavState('advicemanagement')">意见列表</el-menu-item>
          </el-submenu>
          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-notebook-2"></i>
              <span slot="title">切片管理</span>
            </template>
            <el-menu-item index="teachingsclicemanagement" @click="saveNavState('teachingsclicemanagement')">教案切片</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 右侧内容主体 -->
      <el-main>
        <router-view />
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      isCollapse: false,
      // 被激活的地址
      activePath: '',
      flexibleIcon: 'el-icon-caret-left'
    }
  },
  created() {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
  methods: {
    goHomeRage() {
      this.$router.push({
        path: '/'
      })
    },
    logout() {
      // 清空token
      window.sessionStorage.clear()
      // 跳转到登录页
      this.$router.push('/login')
    },
    // 点击按钮折叠与展开
    toggleCollapse() {
      this.isCollapse = !this.isCollapse
      if (this.isCollapse) {
        this.flexibleIcon = 'el-icon-caret-right'
      } else {
        this.flexibleIcon = 'el-icon-caret-left'
      }
    },
    // 保存链接的激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      this.activePath = activePath
    }
  }
}
</script>

<style scoped>
.home-container {
  height: 100%;
  min-height: 850px;
}

.headerContainer {
  min-width: 1200px;
}
.el-header {
  background-color: #3f3c40;
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;
  color: #fff;
  font-size: 20px;
}
.logoContainer {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.logoName {
  margin-left: 15px;
}

.el-aside {
  background-color: #454246;
}
/* 消除左侧边栏一像素的误差 */
.el-menu {
  border-right: none;
}

.el-main {
  background-color: #eaedf1;
  min-width: 1000px;
}

.iconfont {
  margin-right: 10px;
}
.toggle-button {
  background-color: rgb(60, 64, 78);
  font-size: 10px;
  line-height: 24px;
  color: #fff;
  text-align: center;
  letter-spacing: 0.2em;
  /* 鼠标放上去就变成小手 */
  cursor: pointer;
}
</style>
